package com.jack.blog.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.List;

public final class JsonUtil {
    private static final ObjectMapper mapper=new ObjectMapper();

    public static String toJson(Object obj)throws Exception{
        return mapper.writeValueAsString(obj);
    }

    public static <T> List<T> parseJsonList(String json, Class<T> cls)throws Exception{
        return mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class,cls));
    }
}
